package com.leo.base_project.activity.base;

import android.annotation.SuppressLint;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.WindowManager;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.leo.base_project.config.GlobalConfig;
import com.leo.base_project.entity.DaoMaster;
import com.leo.base_project.entity.DaoSession;

/**
 * @program: BaseProject
 * @description: 基础页面实现
 * @author: Leo
 * @create: 2021-03-28 11:36
 **/
@SuppressLint("NonConstantResourceId")
public class BaseActivityX extends AppCompatActivity implements BaseActivity {

    protected DaoMaster.DevOpenHelper devOpenHelper;
    protected DaoMaster daoMaster;
    protected DaoSession daoSession;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initData();
        initView();
    }

    @Override
    public void initData() {
        devOpenHelper = new DaoMaster.DevOpenHelper(this, GlobalConfig.DB_NAME, null);
        daoMaster = new DaoMaster(devOpenHelper.getWritableDatabase());
        daoSession = daoMaster.newSession();
    }

    @Override
    public void initView() {
        // 强制全屏
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        // 强制横屏
        if (getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
        }
    }
}
